package com.adresvseti.wallpaperoid.services;

import java.io.InputStream;

import android.graphics.Bitmap;

public class ImageService {

	/** Decodes and resizes image from input stream asynchronously.
	 * @param stream		Input stream to decode.
	 * @param targetWidth	Maximum target bitmap width.
	 * @param targetHeight	Maximum target bitmap height.
	 * @param callback		Callback method.
	 */
	public void decodeBitmapAsync(InputStream stream, int targetWidth, int targetHeight, final IDecodeBitmapCallback callback) {

		DecodeBitmapTask task = new DecodeBitmapTask(targetWidth, targetHeight, new IDecodeBitmapCallback() {
			
			@Override
			public void success(Bitmap result) {
				
				callback.success(result);
			}
		});
		
		task.execute(stream);		
	}
	
	/** Downloads binary from url asynchronously.
	 * @param url		Url to download.
	 * @param callback	Callback method.
	 */
	public void downloadImageAsync(String url, final IDownloadBinaryCallback callback)
	{
		
			DownloadBinaryTask task = new DownloadBinaryTask(new IDownloadBinaryCallback() {
				
				@Override
				public void success(InputStream inputStream) {
					
					callback.success(inputStream);
					
				}
			});
		
		task.execute(url);	
	}
	
}
